<!DOCTYPE html>
<html>
<div class="wrapper">
<head>
    <title>登录成功</title>
    <meta name="content-type";
          charset="UTF-8">
</head>
<style type="text/css">
    .wrapper {width: 1000px;margin: 20px auto;}
    h2 {text-align: center;}
    .add {margin-bottom: 20px;}
    .add a {text-decoration: none;color: #fff;background-color: #0b1680;padding: 6px;border-radius: 5px;}
    td {text-align: center;}
</style>
<body>
<div>
    <?php
    session_start();
    $username = isset($_SESSION['user']) ? $_SESSION['user'] : "";
    if (!empty($username)) { ?>
        <h2>欢迎您！
        <?php
        echo $username;?></h2>
    <h1>用户管理系统</h1>
            <div class="add">
                <a href="add.php">增加用户</a>
            </div>
            <table width="960" border="1">
                <tr>
                    <th>username</th>
                    <th>password</th>
                    <th>sex</th>
                    <th>qq</th>
                    <th>email</th>
                    <th>phone</th>
                    <th>address</th>
                </tr>

                <?php

                $link = new mysqli("localhost","root","74642486","db_user",3306);

                $sql="select * from tb_user";  // 结果集
                $result=$link->query($sql);

                $newsNum=$result->num_rows;

                for($i=0; $i<$newsNum; $i++){
                    $row = mysqli_fetch_assoc($result);
                    echo "<tr>";
                    echo "<td>{$row['username']}</td>";
                    echo "<td>{$row['password']}</td>";
                    echo "<td>{$row['sex']}</td>";
                    echo "<td>{$row['qq']}</td>";
                    echo "<td>{$row['email']}</td>";
                    echo "<td>{$row['phone']}</td>";
                    echo "<td>{$row['address']}</td>";
                    echo "<td>
							<a href='javascript:del({$row['username']})'>删除</a>
							<a href='edit.php?username={$row['username']}'>修改</a>
						  </td>";
                    echo "</tr>";
                }
                mysqli_free_result($result);
                mysqli_close($link);
                ?>
            </table>
    <?php
    $err = isset($_GET["err"]) ? $_GET["err"] : "";
    switch ($err) {
        case 1:
            echo "添加成功！";
            break;
        case 2:
            echo "删除成功！";
            break;
        case 3:
            echo "修改成功！";
            break;
    }
    ?>
        <script type="text/javascript">
            function del (id) {
                if (confirm("确定删除吗？")){
                    window.location = "action-del.php?id="+id;
                }
            }
        </script>
        </body>
        </html>

        <br/>
        点这里<a href="superlogin.php">退出</a>
</div>
        <?php
    } else { //未登录，无权访问
        ?>
        <h1>你无权访问！！！</h1>
        <?php
    } ?> </div>
</body>
</html>
